{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 1,\n",
    "   \"id\": \"dc7837b7-9705-4192-8b61-e2d6c17deff2\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"import polars as pl\\n\",\n",
    "    \"from perspective.widget import PerspectiveWidget\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 2,\n",
    "   \"id\": \"30a22363-8d7e-4013-b67e-34c3dc492ea9\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (363, 18)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>1</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:33:37&quot;</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>2</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:34:24&quot;</td><td>&quot;601077&quot;</td><td>&quot;渝农商行&quot;</td><td>&quot;买入&quot;</td><td>3.65</td><td>38300.0</td><td>139795.0</td><td>22.37</td><td>0.0</td><td>1.38</td><td>0.0</td><td>-139818.75</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>3</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:36:30&quot;</td><td>&quot;600894&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>4</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:37:25&quot;</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;买入&quot;</td><td>2.59</td><td>54000.0</td><td>139860.0</td><td>22.38</td><td>0.0</td><td>1.42</td><td>0.0</td><td>-139883.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>5</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:38:16&quot;</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>359</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:31:53&quot;</td><td>&quot;002956&quot;</td><td>&quot;西麦食品&quot;</td><td>&quot;卖出&quot;</td><td>14.13</td><td>5000.0</td><td>70650.0</td><td>6.74</td><td>35.35</td><td>0.0</td><td>0.0</td><td>70607.91</td><td>0.000095</td><td>0.0005</td><td>0.0</td></tr><tr><td>360</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:39:57&quot;</td><td>&quot;603214&quot;</td><td>&quot;爱婴室&quot;</td><td>&quot;买入&quot;</td><td>15.84</td><td>3100.0</td><td>49104.0</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-49109.51</td><td>0.000102</td><td>0.0</td><td>0.00001</td></tr><tr><td>361</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:40:55&quot;</td><td>&quot;300132&quot;</td><td>&quot;青松股份&quot;</td><td>&quot;买入&quot;</td><td>5.21</td><td>9600.0</td><td>50016.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50021.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr><tr><td>362</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:43:13&quot;</td><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>&quot;买入&quot;</td><td>5.91</td><td>8400.0</td><td>49644.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49649.0</td><td>0.000101</td><td>0.0</td><td>0.0</td></tr><tr><td>363</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:44:45&quot;</td><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>&quot;买入&quot;</td><td>9.24</td><td>5400.0</td><td>49896.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49901.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (363, 18)\\n\",\n",
    "       \"┌──────┬──────────┬────────────┬──────────┬───┬────────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商     ┆ 交易日期   ┆ 交易时间 ┆ … ┆ 发生金额   ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 │\\n\",\n",
    "       \"│ ---  ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---        ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str      ┆ date       ┆ str      ┆   ┆ f64        ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════════╪════════════╪══════════╪═══╪════════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 1    ┆ 湘财     ┆ 2022-07-11 ┆ 09:33:37 ┆ … ┆ -139342.29 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 2    ┆ 湘财     ┆ 2022-07-11 ┆ 09:34:24 ┆ … ┆ -139818.75 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 3    ┆ 湘财     ┆ 2022-07-11 ┆ 09:36:30 ┆ … ┆ -139979.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 4    ┆ 湘财     ┆ 2022-07-11 ┆ 09:37:25 ┆ … ┆ -139883.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 5    ┆ 湘财     ┆ 2022-07-11 ┆ 09:38:16 ┆ … ┆ -140526.48 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ …    ┆ …        ┆ …          ┆ …        ┆ … ┆ …          ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 359  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:31:53 ┆ … ┆ 70607.91   ┆ 0.000095 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ 360  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:39:57 ┆ … ┆ -49109.51  ┆ 0.000102 ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 361  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:40:55 ┆ … ┆ -50021.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 362  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:43:13 ┆ … ┆ -49649.0   ┆ 0.000101 ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 363  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:44:45 ┆ … ┆ -49901.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"└──────┴──────────┴────────────┴──────────┴───┴────────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 2,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"df = pl.read_parquet(\\\"stock_trades.parquet\\\")\\n\",\n",
    "    \"df = df.sort(\\\"交易日期\\\", \\\"交易时间\\\", \\\"证券代码\\\")\\n\",\n",
    "    \"df = df.with_columns(\\n\",\n",
    "    \"    pl.col(\\\"交易时间\\\").cast(pl.String),\\n\",\n",
    "    \"    手续费率=pl.col(\\\"手续费\\\") / pl.col(\\\"成交金额\\\"),\\n\",\n",
    "    \"    印花税率=pl.col(\\\"印花税\\\") / pl.col(\\\"成交金额\\\"),\\n\",\n",
    "    \"    过户费率=pl.col(\\\"过户费\\\") / pl.col(\\\"成交金额\\\"),\\n\",\n",
    "    \")\\n\",\n",
    "    \"df = df.with_row_index(\\\"序号\\\", 1)\\n\",\n",
    "    \"df\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 3,\n",
    "   \"id\": \"28cf6e62-6fd6-49d4-9727-dfe561ea7463\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (2, 2)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>券商</th><th>count</th></tr><tr><td>str</td><td>u32</td></tr></thead><tbody><tr><td>&quot;湘财&quot;</td><td>19</td></tr><tr><td>&quot;海通普通&quot;</td><td>33</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (2, 2)\\n\",\n",
    "       \"┌──────────┬───────┐\\n\",\n",
    "       \"│ 券商     ┆ count │\\n\",\n",
    "       \"│ ---      ┆ ---   │\\n\",\n",
    "       \"│ str      ┆ u32   │\\n\",\n",
    "       \"╞══════════╪═══════╡\\n\",\n",
    "       \"│ 湘财     ┆ 19    │\\n\",\n",
    "       \"│ 海通普通 ┆ 33    │\\n\",\n",
    "       \"└──────────┴───────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 3,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"df.filter(pl.col(\\\"手续费\\\") < 5)[\\\"券商\\\"].value_counts()\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 4,\n",
    "   \"id\": \"12fe9352-1457-4a68-a700-d6c33fa2eafd\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (53, 18)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>320</td><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>&quot;09:34:39&quot;</td><td>&quot;300642&quot;</td><td>&quot;透景生命&quot;</td><td>&quot;卖出&quot;</td><td>18.106</td><td>2500.0</td><td>45266.0</td><td>5.0</td><td>45.26</td><td>0.0</td><td>0.0</td><td>45215.74</td><td>0.00011</td><td>0.001</td><td>0.0</td></tr><tr><td>323</td><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>&quot;09:39:25&quot;</td><td>&quot;600333&quot;</td><td>&quot;长春燃气&quot;</td><td>&quot;卖出&quot;</td><td>5.04</td><td>3900.0</td><td>19656.0</td><td>5.0</td><td>19.64</td><td>0.23</td><td>0.0</td><td>19631.13</td><td>0.000254</td><td>0.000999</td><td>0.000012</td></tr><tr><td>325</td><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>&quot;10:03:59&quot;</td><td>&quot;600525&quot;</td><td>&quot;长园集团&quot;</td><td>&quot;买入&quot;</td><td>4.88</td><td>8500.0</td><td>41480.0</td><td>5.0</td><td>0.0</td><td>0.35</td><td>0.0</td><td>-41485.35</td><td>0.000121</td><td>0.0</td><td>0.000008</td></tr><tr><td>327</td><td>&quot;海通两融&quot;</td><td>2023-09-01</td><td>&quot;10:22:36&quot;</td><td>&quot;300889&quot;</td><td>&quot;爱克股份&quot;</td><td>&quot;卖出&quot;</td><td>15.22</td><td>1500.0</td><td>22830.0</td><td>5.0</td><td>11.42</td><td>0.0</td><td>0.0</td><td>22813.58</td><td>0.000219</td><td>0.0005</td><td>0.0</td></tr><tr><td>329</td><td>&quot;海通两融&quot;</td><td>2023-09-01</td><td>&quot;10:23:28&quot;</td><td>&quot;300889&quot;</td><td>&quot;爱克股份&quot;</td><td>&quot;卖出&quot;</td><td>15.21</td><td>1700.0</td><td>25857.0</td><td>5.0</td><td>12.92</td><td>0.0</td><td>0.0</td><td>25839.08</td><td>0.000193</td><td>0.0005</td><td>0.0</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>322</td><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>&quot;09:36:13&quot;</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;卖出&quot;</td><td>9.36</td><td>10600.0</td><td>99216.0</td><td>10.91</td><td>99.24</td><td>1.0</td><td>0.0</td><td>99104.85</td><td>0.00011</td><td>0.001</td><td>0.00001</td></tr><tr><td>319</td><td>&quot;海通两融&quot;</td><td>2023-08-09</td><td>&quot;10:12:16&quot;</td><td>&quot;600336&quot;</td><td>&quot;澳柯玛&quot;</td><td>&quot;买入&quot;</td><td>5.72</td><td>17400.0</td><td>99528.0</td><td>10.95</td><td>0.0</td><td>1.0</td><td>0.0</td><td>-99539.95</td><td>0.00011</td><td>0.0</td><td>0.00001</td></tr><tr><td>324</td><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>&quot;09:58:46&quot;</td><td>&quot;603626&quot;</td><td>&quot;科森科技&quot;</td><td>&quot;买入&quot;</td><td>6.35</td><td>15700.0</td><td>99695.0</td><td>10.97</td><td>0.0</td><td>1.02</td><td>0.0</td><td>-99706.99</td><td>0.00011</td><td>0.0</td><td>0.00001</td></tr><tr><td>316</td><td>&quot;海通两融&quot;</td><td>2023-08-04</td><td>&quot;10:07:37&quot;</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;买入&quot;</td><td>9.43</td><td>10600.0</td><td>99958.0</td><td>11.0</td><td>0.0</td><td>1.01</td><td>0.0</td><td>-99970.01</td><td>0.00011</td><td>0.0</td><td>0.00001</td></tr><tr><td>340</td><td>&quot;海通两融&quot;</td><td>2023-09-12</td><td>&quot;14:31:39&quot;</td><td>&quot;603626&quot;</td><td>&quot;科森科技&quot;</td><td>&quot;卖出&quot;</td><td>7.43</td><td>15700.0</td><td>116651.0</td><td>11.13</td><td>58.32</td><td>1.17</td><td>0.0</td><td>116580.38</td><td>0.000095</td><td>0.0005</td><td>0.00001</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (53, 18)\\n\",\n",
    "       \"┌──────┬──────────┬────────────┬──────────┬───┬───────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商     ┆ 交易日期   ┆ 交易时间 ┆ … ┆ 发生金额  ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 │\\n\",\n",
    "       \"│ ---  ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---       ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str      ┆ date       ┆ str      ┆   ┆ f64       ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════════╪════════════╪══════════╪═══╪═══════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 320  ┆ 海通两融 ┆ 2023-08-22 ┆ 09:34:39 ┆ … ┆ 45215.74  ┆ 0.00011  ┆ 0.001    ┆ 0.0      │\\n\",\n",
    "       \"│ 323  ┆ 海通两融 ┆ 2023-08-22 ┆ 09:39:25 ┆ … ┆ 19631.13  ┆ 0.000254 ┆ 0.000999 ┆ 0.000012 │\\n\",\n",
    "       \"│ 325  ┆ 海通两融 ┆ 2023-08-22 ┆ 10:03:59 ┆ … ┆ -41485.35 ┆ 0.000121 ┆ 0.0      ┆ 0.000008 │\\n\",\n",
    "       \"│ 327  ┆ 海通两融 ┆ 2023-09-01 ┆ 10:22:36 ┆ … ┆ 22813.58  ┆ 0.000219 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ 329  ┆ 海通两融 ┆ 2023-09-01 ┆ 10:23:28 ┆ … ┆ 25839.08  ┆ 0.000193 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ …    ┆ …        ┆ …          ┆ …        ┆ … ┆ …         ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 322  ┆ 海通两融 ┆ 2023-08-22 ┆ 09:36:13 ┆ … ┆ 99104.85  ┆ 0.00011  ┆ 0.001    ┆ 0.00001  │\\n\",\n",
    "       \"│ 319  ┆ 海通两融 ┆ 2023-08-09 ┆ 10:12:16 ┆ … ┆ -99539.95 ┆ 0.00011  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 324  ┆ 海通两融 ┆ 2023-08-22 ┆ 09:58:46 ┆ … ┆ -99706.99 ┆ 0.00011  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 316  ┆ 海通两融 ┆ 2023-08-04 ┆ 10:07:37 ┆ … ┆ -99970.01 ┆ 0.00011  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 340  ┆ 海通两融 ┆ 2023-09-12 ┆ 14:31:39 ┆ … ┆ 116580.38 ┆ 0.000095 ┆ 0.0005   ┆ 0.00001  │\\n\",\n",
    "       \"└──────┴──────────┴────────────┴──────────┴───┴───────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 4,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"df.filter(pl.col(\\\"券商\\\") == \\\"海通两融\\\").sort(\\\"手续费\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 5,\n",
    "   \"id\": \"0e7c38ea-8556-4c53-8dcc-396a9a2dbfd2\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"59ee5d55eba6451a8a4f7fcdc7129dc6\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"PerspectiveWidget(binding_mode='server', columns=['序号', '券商', '交易日期', '交易时间', '证券代码', '证券名称', '买卖标志', '成交价格', …\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 5,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"PerspectiveWidget(df)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 6,\n",
    "   \"id\": \"b34c7795-def9-45a5-86a7-7697a8d990a9\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (152, 4)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>证券代码</th><th>证券名称</th><th>len</th><th>买卖标志</th></tr><tr><td>str</td><td>str</td><td>u32</td><td>list[str]</td></tr></thead><tbody><tr><td>&quot;002996&quot;</td><td>&quot;顺博合金&quot;</td><td>3</td><td>[&quot;买入&quot;, &quot;卖出&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>1</td><td>[&quot;买入&quot;]</td></tr><tr><td>&quot;300304&quot;</td><td>&quot;云意电气&quot;</td><td>2</td><td>[&quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;688660&quot;</td><td>&quot;电气风电&quot;</td><td>1</td><td>[&quot;买入&quot;]</td></tr><tr><td>&quot;000096&quot;</td><td>&quot;广聚能源&quot;</td><td>2</td><td>[&quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;605258&quot;</td><td>&quot;协和电子&quot;</td><td>2</td><td>[&quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;300283&quot;</td><td>&quot;温州宏丰&quot;</td><td>3</td><td>[&quot;买入&quot;, &quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;300155&quot;</td><td>&quot;安居宝&quot;</td><td>3</td><td>[&quot;买入&quot;, &quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;688069&quot;</td><td>&quot;德林海环保&quot;</td><td>2</td><td>[&quot;买入&quot;, &quot;卖出&quot;]</td></tr><tr><td>&quot;000532&quot;</td><td>&quot;华金资本&quot;</td><td>2</td><td>[&quot;买入&quot;, &quot;卖出&quot;]</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (152, 4)\\n\",\n",
    "       \"┌──────────┬────────────┬─────┬──────────────────────────┐\\n\",\n",
    "       \"│ 证券代码 ┆ 证券名称   ┆ len ┆ 买卖标志                 │\\n\",\n",
    "       \"│ ---      ┆ ---        ┆ --- ┆ ---                      │\\n\",\n",
    "       \"│ str      ┆ str        ┆ u32 ┆ list[str]                │\\n\",\n",
    "       \"╞══════════╪════════════╪═════╪══════════════════════════╡\\n\",\n",
    "       \"│ 002996   ┆ 顺博合金   ┆ 3   ┆ [\\\"买入\\\", \\\"卖出\\\", \\\"卖出\\\"] │\\n\",\n",
    "       \"│ 002111   ┆ 威海广泰   ┆ 1   ┆ [\\\"买入\\\"]                 │\\n\",\n",
    "       \"│ 300304   ┆ 云意电气   ┆ 2   ┆ [\\\"买入\\\", \\\"卖出\\\"]         │\\n\",\n",
    "       \"│ 688660   ┆ 电气风电   ┆ 1   ┆ [\\\"买入\\\"]                 │\\n\",\n",
    "       \"│ 000096   ┆ 广聚能源   ┆ 2   ┆ [\\\"买入\\\", \\\"卖出\\\"]         │\\n\",\n",
    "       \"│ …        ┆ …          ┆ …   ┆ …                        │\\n\",\n",
    "       \"│ 605258   ┆ 协和电子   ┆ 2   ┆ [\\\"买入\\\", \\\"卖出\\\"]         │\\n\",\n",
    "       \"│ 300283   ┆ 温州宏丰   ┆ 3   ┆ [\\\"买入\\\", \\\"买入\\\", \\\"卖出\\\"] │\\n\",\n",
    "       \"│ 300155   ┆ 安居宝     ┆ 3   ┆ [\\\"买入\\\", \\\"买入\\\", \\\"卖出\\\"] │\\n\",\n",
    "       \"│ 688069   ┆ 德林海环保 ┆ 2   ┆ [\\\"买入\\\", \\\"卖出\\\"]         │\\n\",\n",
    "       \"│ 000532   ┆ 华金资本   ┆ 2   ┆ [\\\"买入\\\", \\\"卖出\\\"]         │\\n\",\n",
    "       \"└──────────┴────────────┴─────┴──────────────────────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 6,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"df.group_by(\\\"证券代码\\\", \\\"证券名称\\\").agg(pl.len(), pl.col(\\\"买卖标志\\\"))\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 7,\n",
    "   \"id\": \"932101fe-089c-4dfa-8dd8-213429edbf5c\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"d1 = df.join(\\n\",\n",
    "    \"    df.group_by(\\\"证券代码\\\", \\\"证券名称\\\")\\n\",\n",
    "    \"    .agg(\\n\",\n",
    "    \"        结余数量=(\\n\",\n",
    "    \"            pl.when(pl.col(\\\"买卖标志\\\") == \\\"卖出\\\")\\n\",\n",
    "    \"            .then(-pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .when(pl.col(\\\"买卖标志\\\") == \\\"买入\\\")\\n\",\n",
    "    \"            .then(pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .sum()\\n\",\n",
    "    \"        ),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .filter(pl.col(\\\"结余数量\\\") < 0),\\n\",\n",
    "    \"    on=\\\"证券代码\\\",\\n\",\n",
    "    \"    how=\\\"anti\\\",\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 8,\n",
    "   \"id\": \"607366a6-088a-487f-9f6c-ba8323a5e4a5\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"(363, 18)\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 8,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"df.shape\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 9,\n",
    "   \"id\": \"ba28894c-9130-4a60-af45-d7387b5ae601\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (358, 18)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>1</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:33:37&quot;</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>2</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:34:24&quot;</td><td>&quot;601077&quot;</td><td>&quot;渝农商行&quot;</td><td>&quot;买入&quot;</td><td>3.65</td><td>38300.0</td><td>139795.0</td><td>22.37</td><td>0.0</td><td>1.38</td><td>0.0</td><td>-139818.75</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>3</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:36:30&quot;</td><td>&quot;600894&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>4</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:37:25&quot;</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;买入&quot;</td><td>2.59</td><td>54000.0</td><td>139860.0</td><td>22.38</td><td>0.0</td><td>1.42</td><td>0.0</td><td>-139883.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>5</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:38:16&quot;</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>359</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:31:53&quot;</td><td>&quot;002956&quot;</td><td>&quot;西麦食品&quot;</td><td>&quot;卖出&quot;</td><td>14.13</td><td>5000.0</td><td>70650.0</td><td>6.74</td><td>35.35</td><td>0.0</td><td>0.0</td><td>70607.91</td><td>0.000095</td><td>0.0005</td><td>0.0</td></tr><tr><td>360</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:39:57&quot;</td><td>&quot;603214&quot;</td><td>&quot;爱婴室&quot;</td><td>&quot;买入&quot;</td><td>15.84</td><td>3100.0</td><td>49104.0</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-49109.51</td><td>0.000102</td><td>0.0</td><td>0.00001</td></tr><tr><td>361</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:40:55&quot;</td><td>&quot;300132&quot;</td><td>&quot;青松股份&quot;</td><td>&quot;买入&quot;</td><td>5.21</td><td>9600.0</td><td>50016.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50021.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr><tr><td>362</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:43:13&quot;</td><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>&quot;买入&quot;</td><td>5.91</td><td>8400.0</td><td>49644.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49649.0</td><td>0.000101</td><td>0.0</td><td>0.0</td></tr><tr><td>363</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:44:45&quot;</td><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>&quot;买入&quot;</td><td>9.24</td><td>5400.0</td><td>49896.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49901.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (358, 18)\\n\",\n",
    "       \"┌──────┬──────────┬────────────┬──────────┬───┬────────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商     ┆ 交易日期   ┆ 交易时间 ┆ … ┆ 发生金额   ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 │\\n\",\n",
    "       \"│ ---  ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---        ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str      ┆ date       ┆ str      ┆   ┆ f64        ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════════╪════════════╪══════════╪═══╪════════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 1    ┆ 湘财     ┆ 2022-07-11 ┆ 09:33:37 ┆ … ┆ -139342.29 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 2    ┆ 湘财     ┆ 2022-07-11 ┆ 09:34:24 ┆ … ┆ -139818.75 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 3    ┆ 湘财     ┆ 2022-07-11 ┆ 09:36:30 ┆ … ┆ -139979.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 4    ┆ 湘财     ┆ 2022-07-11 ┆ 09:37:25 ┆ … ┆ -139883.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 5    ┆ 湘财     ┆ 2022-07-11 ┆ 09:38:16 ┆ … ┆ -140526.48 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ …    ┆ …        ┆ …          ┆ …        ┆ … ┆ …          ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 359  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:31:53 ┆ … ┆ 70607.91   ┆ 0.000095 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ 360  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:39:57 ┆ … ┆ -49109.51  ┆ 0.000102 ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 361  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:40:55 ┆ … ┆ -50021.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 362  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:43:13 ┆ … ┆ -49649.0   ┆ 0.000101 ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 363  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:44:45 ┆ … ┆ -49901.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"└──────┴──────────┴────────────┴──────────┴───┴────────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 9,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d1\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 10,\n",
    "   \"id\": \"5b5bc15a-f107-4741-a74d-3411fd2ae00e\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"datetime.date(2022, 7, 11)\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 10,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"start_date = df[\\\"交易日期\\\"].min()\\n\",\n",
    "    \"start_date\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 11,\n",
    "   \"id\": \"93b054e2-7dba-4c3e-82d0-53884ab36101\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"datetime.date(2023, 10, 31)\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 11,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"end_date = df[\\\"交易日期\\\"].max()\\n\",\n",
    "    \"end_date\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 12,\n",
    "   \"id\": \"ba7cb8ec-babc-42cb-9494-1dd8bc8a4b07\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (478, 1)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>日期</th></tr><tr><td>date</td></tr></thead><tbody><tr><td>2022-07-11</td></tr><tr><td>2022-07-12</td></tr><tr><td>2022-07-13</td></tr><tr><td>2022-07-14</td></tr><tr><td>2022-07-15</td></tr><tr><td>&hellip;</td></tr><tr><td>2023-10-27</td></tr><tr><td>2023-10-28</td></tr><tr><td>2023-10-29</td></tr><tr><td>2023-10-30</td></tr><tr><td>2023-10-31</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (478, 1)\\n\",\n",
    "       \"┌────────────┐\\n\",\n",
    "       \"│ 日期       │\\n\",\n",
    "       \"│ ---        │\\n\",\n",
    "       \"│ date       │\\n\",\n",
    "       \"╞════════════╡\\n\",\n",
    "       \"│ 2022-07-11 │\\n\",\n",
    "       \"│ 2022-07-12 │\\n\",\n",
    "       \"│ 2022-07-13 │\\n\",\n",
    "       \"│ 2022-07-14 │\\n\",\n",
    "       \"│ 2022-07-15 │\\n\",\n",
    "       \"│ …          │\\n\",\n",
    "       \"│ 2023-10-27 │\\n\",\n",
    "       \"│ 2023-10-28 │\\n\",\n",
    "       \"│ 2023-10-29 │\\n\",\n",
    "       \"│ 2023-10-30 │\\n\",\n",
    "       \"│ 2023-10-31 │\\n\",\n",
    "       \"└────────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 12,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"k1 = pl.select(日期=pl.date_range(start_date, end_date))\\n\",\n",
    "    \"k1\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 13,\n",
    "   \"id\": \"b16f8214-f07b-47d6-a200-39dc6c0798d7\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (152, 1)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>证券代码</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;000096&quot;</td></tr><tr><td>&quot;000532&quot;</td></tr><tr><td>&quot;000559&quot;</td></tr><tr><td>&quot;000599&quot;</td></tr><tr><td>&quot;000655&quot;</td></tr><tr><td>&hellip;</td></tr><tr><td>&quot;688299&quot;</td></tr><tr><td>&quot;688321&quot;</td></tr><tr><td>&quot;688360&quot;</td></tr><tr><td>&quot;688393&quot;</td></tr><tr><td>&quot;688660&quot;</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (152, 1)\\n\",\n",
    "       \"┌──────────┐\\n\",\n",
    "       \"│ 证券代码 │\\n\",\n",
    "       \"│ ---      │\\n\",\n",
    "       \"│ str      │\\n\",\n",
    "       \"╞══════════╡\\n\",\n",
    "       \"│ 000096   │\\n\",\n",
    "       \"│ 000532   │\\n\",\n",
    "       \"│ 000559   │\\n\",\n",
    "       \"│ 000599   │\\n\",\n",
    "       \"│ 000655   │\\n\",\n",
    "       \"│ …        │\\n\",\n",
    "       \"│ 688299   │\\n\",\n",
    "       \"│ 688321   │\\n\",\n",
    "       \"│ 688360   │\\n\",\n",
    "       \"│ 688393   │\\n\",\n",
    "       \"│ 688660   │\\n\",\n",
    "       \"└──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 13,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"k2 = df[\\\"证券代码\\\"].unique().sort().to_frame()\\n\",\n",
    "    \"k2\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 14,\n",
    "   \"id\": \"cebcec9b-58da-473e-93c6-08ee04eb44cf\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"k = k1.join(k2, how=\\\"cross\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 15,\n",
    "   \"id\": \"2f3782dd-3c35-4038-be89-26379c41c82f\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"d2 = (\\n\",\n",
    "    \"    k.join(\\n\",\n",
    "    \"        d1, left_on=[\\\"日期\\\", \\\"证券代码\\\"], right_on=[\\\"交易日期\\\", \\\"证券代码\\\"], how=\\\"left\\\"\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .sort(\\\"日期\\\", \\\"证券代码\\\")\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        结余数量=(\\n\",\n",
    "    \"            pl.when(pl.col(\\\"买卖标志\\\") == \\\"买入\\\")\\n\",\n",
    "    \"            .then(pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .when(pl.col(\\\"买卖标志\\\") == \\\"卖出\\\")\\n\",\n",
    "    \"            .then(-pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .otherwise(0)\\n\",\n",
    "    \"            .cum_sum()\\n\",\n",
    "    \"            .over(\\\"证券代码\\\")\\n\",\n",
    "    \"        ),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .filter(pl.col.结余数量 > 0)\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 16,\n",
    "   \"id\": \"ba81bf3d-4256-4fed-add9-34fd9c919707\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (10, 3)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>n</th><th>name</th><th>runing_n</th></tr><tr><td>i64</td><td>str</td><td>i64</td></tr></thead><tbody><tr><td>400</td><td>&quot;A&quot;</td><td>400</td></tr><tr><td>800</td><td>&quot;A&quot;</td><td>1200</td></tr><tr><td>-3300</td><td>&quot;A&quot;</td><td>-2100</td></tr><tr><td>4400</td><td>&quot;A&quot;</td><td>2300</td></tr><tr><td>2200</td><td>&quot;A&quot;</td><td>4500</td></tr><tr><td>1400</td><td>&quot;B&quot;</td><td>1400</td></tr><tr><td>500</td><td>&quot;B&quot;</td><td>1900</td></tr><tr><td>-300</td><td>&quot;B&quot;</td><td>1600</td></tr><tr><td>-400</td><td>&quot;B&quot;</td><td>1200</td></tr><tr><td>4200</td><td>&quot;B&quot;</td><td>5400</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (10, 3)\\n\",\n",
    "       \"┌───────┬──────┬──────────┐\\n\",\n",
    "       \"│ n     ┆ name ┆ runing_n │\\n\",\n",
    "       \"│ ---   ┆ ---  ┆ ---      │\\n\",\n",
    "       \"│ i64   ┆ str  ┆ i64      │\\n\",\n",
    "       \"╞═══════╪══════╪══════════╡\\n\",\n",
    "       \"│ 400   ┆ A    ┆ 400      │\\n\",\n",
    "       \"│ 800   ┆ A    ┆ 1200     │\\n\",\n",
    "       \"│ -3300 ┆ A    ┆ -2100    │\\n\",\n",
    "       \"│ 4400  ┆ A    ┆ 2300     │\\n\",\n",
    "       \"│ 2200  ┆ A    ┆ 4500     │\\n\",\n",
    "       \"│ 1400  ┆ B    ┆ 1400     │\\n\",\n",
    "       \"│ 500   ┆ B    ┆ 1900     │\\n\",\n",
    "       \"│ -300  ┆ B    ┆ 1600     │\\n\",\n",
    "       \"│ -400  ┆ B    ┆ 1200     │\\n\",\n",
    "       \"│ 4200  ┆ B    ┆ 5400     │\\n\",\n",
    "       \"└───────┴──────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 16,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"dd1 = pl.DataFrame({\\\"n\\\": [400, 800, -3300, 4400, 2200]}).with_columns(name=pl.lit(\\\"A\\\"))\\n\",\n",
    "    \"dd2 = pl.DataFrame({\\\"n\\\": [1400, 500, -300, -400, 4200]}).with_columns(name=pl.lit(\\\"B\\\"))\\n\",\n",
    "    \"dd = pl.concat([dd1, dd2])\\n\",\n",
    "    \"dd.with_columns(\\n\",\n",
    "    \"    runing_n=pl.col.n.cum_sum().over(\\\"name\\\"),\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 17,\n",
    "   \"id\": \"125d085c-522d-4ca3-923c-a5774e985bae\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"9d24e39f03e443b08528fa76f0ceb73d\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"PerspectiveWidget(binding_mode='server', columns=['日期', '证券代码', '序号', '券商', '交易时间', '证券名称', '买卖标志', '成交价格', '成…\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 17,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"PerspectiveWidget(d2)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 18,\n",
    "   \"id\": \"7e5d5db3-9eeb-4abc-84db-d8fad0f160e5\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"import tushare as ts\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 19,\n",
    "   \"id\": \"b97a926e-990f-459b-ba2c-fc16d532f03d\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"pro = ts.pro_api()\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 20,\n",
    "   \"id\": \"4ac5ca0a-d8ad-48f1-bc56-0f69a6948a3d\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"'20220711'\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 20,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"f\\\"{start_date:%Y%m%d}\\\"\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 21,\n",
    "   \"id\": \"c1df77c8-c3d5-42af-b59a-50d99a0842f8\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"'20231031'\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 21,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"format(end_date, \\\"%Y%m%d\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 22,\n",
    "   \"id\": \"1406267b-c1ac-48ee-86e7-d26836e3186f\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (318, 11)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>ts_code</th><th>trade_date</th><th>open</th><th>high</th><th>low</th><th>close</th><th>pre_close</th><th>change</th><th>pct_chg</th><th>vol</th><th>amount</th></tr><tr><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20231031&quot;</td><td>14.75</td><td>14.9</td><td>14.59</td><td>14.7</td><td>14.75</td><td>-0.05</td><td>-0.339</td><td>65859.96</td><td>96984.271</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20231030&quot;</td><td>13.88</td><td>14.89</td><td>13.88</td><td>14.75</td><td>13.93</td><td>0.82</td><td>5.8866</td><td>123932.16</td><td>180119.372</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20231027&quot;</td><td>13.7</td><td>13.98</td><td>13.51</td><td>13.93</td><td>13.64</td><td>0.29</td><td>2.1261</td><td>35782.0</td><td>49386.168</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20231026&quot;</td><td>13.49</td><td>13.68</td><td>13.4</td><td>13.64</td><td>13.62</td><td>0.02</td><td>0.1468</td><td>19215.0</td><td>26005.866</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20231025&quot;</td><td>13.65</td><td>13.77</td><td>13.58</td><td>13.62</td><td>13.67</td><td>-0.05</td><td>-0.3658</td><td>18484.0</td><td>25274.163</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20220715&quot;</td><td>13.61</td><td>13.66</td><td>13.12</td><td>13.13</td><td>13.59</td><td>-0.46</td><td>-3.3848</td><td>32967.65</td><td>44114.064</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20220714&quot;</td><td>13.54</td><td>13.75</td><td>13.5</td><td>13.59</td><td>13.54</td><td>0.05</td><td>0.3693</td><td>21967.0</td><td>29851.164</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20220713&quot;</td><td>13.55</td><td>13.63</td><td>13.39</td><td>13.54</td><td>13.61</td><td>-0.07</td><td>-0.5143</td><td>22793.0</td><td>30714.624</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20220712&quot;</td><td>13.65</td><td>13.69</td><td>13.41</td><td>13.61</td><td>13.65</td><td>-0.04</td><td>-0.293</td><td>29679.0</td><td>40146.31</td></tr><tr><td>&quot;002462.SZ&quot;</td><td>&quot;20220711&quot;</td><td>13.2</td><td>13.96</td><td>13.07</td><td>13.65</td><td>13.18</td><td>0.47</td><td>3.566</td><td>62827.0</td><td>85869.11</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (318, 11)\\n\",\n",
    "       \"┌───────────┬────────────┬───────┬───────┬───┬────────┬─────────┬───────────┬────────────┐\\n\",\n",
    "       \"│ ts_code   ┆ trade_date ┆ open  ┆ high  ┆ … ┆ change ┆ pct_chg ┆ vol       ┆ amount     │\\n\",\n",
    "       \"│ ---       ┆ ---        ┆ ---   ┆ ---   ┆   ┆ ---    ┆ ---     ┆ ---       ┆ ---        │\\n\",\n",
    "       \"│ str       ┆ str        ┆ f64   ┆ f64   ┆   ┆ f64    ┆ f64     ┆ f64       ┆ f64        │\\n\",\n",
    "       \"╞═══════════╪════════════╪═══════╪═══════╪═══╪════════╪═════════╪═══════════╪════════════╡\\n\",\n",
    "       \"│ 002462.SZ ┆ 20231031   ┆ 14.75 ┆ 14.9  ┆ … ┆ -0.05  ┆ -0.339  ┆ 65859.96  ┆ 96984.271  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20231030   ┆ 13.88 ┆ 14.89 ┆ … ┆ 0.82   ┆ 5.8866  ┆ 123932.16 ┆ 180119.372 │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20231027   ┆ 13.7  ┆ 13.98 ┆ … ┆ 0.29   ┆ 2.1261  ┆ 35782.0   ┆ 49386.168  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20231026   ┆ 13.49 ┆ 13.68 ┆ … ┆ 0.02   ┆ 0.1468  ┆ 19215.0   ┆ 26005.866  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20231025   ┆ 13.65 ┆ 13.77 ┆ … ┆ -0.05  ┆ -0.3658 ┆ 18484.0   ┆ 25274.163  │\\n\",\n",
    "       \"│ …         ┆ …          ┆ …     ┆ …     ┆ … ┆ …      ┆ …       ┆ …         ┆ …          │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20220715   ┆ 13.61 ┆ 13.66 ┆ … ┆ -0.46  ┆ -3.3848 ┆ 32967.65  ┆ 44114.064  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20220714   ┆ 13.54 ┆ 13.75 ┆ … ┆ 0.05   ┆ 0.3693  ┆ 21967.0   ┆ 29851.164  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20220713   ┆ 13.55 ┆ 13.63 ┆ … ┆ -0.07  ┆ -0.5143 ┆ 22793.0   ┆ 30714.624  │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20220712   ┆ 13.65 ┆ 13.69 ┆ … ┆ -0.04  ┆ -0.293  ┆ 29679.0   ┆ 40146.31   │\\n\",\n",
    "       \"│ 002462.SZ ┆ 20220711   ┆ 13.2  ┆ 13.96 ┆ … ┆ 0.47   ┆ 3.566   ┆ 62827.0   ┆ 85869.11   │\\n\",\n",
    "       \"└───────────┴────────────┴───────┴───────┴───┴────────┴─────────┴───────────┴────────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 22,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"hq = pro.daily(\\n\",\n",
    "    \"    ts_code=\\\"002462.SZ\\\",\\n\",\n",
    "    \"    start_date=format(start_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \"    end_date=format(end_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \")\\n\",\n",
    "    \"hq = pl.from_pandas(hq)\\n\",\n",
    "    \"hq\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 23,\n",
    "   \"id\": \"990fbf58-448b-440d-9ea0-dbd4f05e3de2\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (358, 18)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>1</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:33:37&quot;</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>2</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:34:24&quot;</td><td>&quot;601077&quot;</td><td>&quot;渝农商行&quot;</td><td>&quot;买入&quot;</td><td>3.65</td><td>38300.0</td><td>139795.0</td><td>22.37</td><td>0.0</td><td>1.38</td><td>0.0</td><td>-139818.75</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>3</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:36:30&quot;</td><td>&quot;600894&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>4</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:37:25&quot;</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;买入&quot;</td><td>2.59</td><td>54000.0</td><td>139860.0</td><td>22.38</td><td>0.0</td><td>1.42</td><td>0.0</td><td>-139883.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>5</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:38:16&quot;</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>359</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:31:53&quot;</td><td>&quot;002956&quot;</td><td>&quot;西麦食品&quot;</td><td>&quot;卖出&quot;</td><td>14.13</td><td>5000.0</td><td>70650.0</td><td>6.74</td><td>35.35</td><td>0.0</td><td>0.0</td><td>70607.91</td><td>0.000095</td><td>0.0005</td><td>0.0</td></tr><tr><td>360</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:39:57&quot;</td><td>&quot;603214&quot;</td><td>&quot;爱婴室&quot;</td><td>&quot;买入&quot;</td><td>15.84</td><td>3100.0</td><td>49104.0</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-49109.51</td><td>0.000102</td><td>0.0</td><td>0.00001</td></tr><tr><td>361</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:40:55&quot;</td><td>&quot;300132&quot;</td><td>&quot;青松股份&quot;</td><td>&quot;买入&quot;</td><td>5.21</td><td>9600.0</td><td>50016.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50021.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr><tr><td>362</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:43:13&quot;</td><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>&quot;买入&quot;</td><td>5.91</td><td>8400.0</td><td>49644.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49649.0</td><td>0.000101</td><td>0.0</td><td>0.0</td></tr><tr><td>363</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:44:45&quot;</td><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>&quot;买入&quot;</td><td>9.24</td><td>5400.0</td><td>49896.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49901.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (358, 18)\\n\",\n",
    "       \"┌──────┬──────────┬────────────┬──────────┬───┬────────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商     ┆ 交易日期   ┆ 交易时间 ┆ … ┆ 发生金额   ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 │\\n\",\n",
    "       \"│ ---  ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---        ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str      ┆ date       ┆ str      ┆   ┆ f64        ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════════╪════════════╪══════════╪═══╪════════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 1    ┆ 湘财     ┆ 2022-07-11 ┆ 09:33:37 ┆ … ┆ -139342.29 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 2    ┆ 湘财     ┆ 2022-07-11 ┆ 09:34:24 ┆ … ┆ -139818.75 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 3    ┆ 湘财     ┆ 2022-07-11 ┆ 09:36:30 ┆ … ┆ -139979.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 4    ┆ 湘财     ┆ 2022-07-11 ┆ 09:37:25 ┆ … ┆ -139883.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 5    ┆ 湘财     ┆ 2022-07-11 ┆ 09:38:16 ┆ … ┆ -140526.48 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ …    ┆ …        ┆ …          ┆ …        ┆ … ┆ …          ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 359  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:31:53 ┆ … ┆ 70607.91   ┆ 0.000095 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ 360  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:39:57 ┆ … ┆ -49109.51  ┆ 0.000102 ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 361  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:40:55 ┆ … ┆ -50021.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 362  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:43:13 ┆ … ┆ -49649.0   ┆ 0.000101 ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 363  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:44:45 ┆ … ┆ -49901.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"└──────┴──────────┴────────────┴──────────┴───┴────────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 23,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d1\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 24,\n",
    "   \"id\": \"85e4b20b-ebf5-4401-8400-9899057bd353\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (4_489, 19)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>日期</th><th>证券代码</th><th>序号</th><th>券商</th><th>交易时间</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th><th>结余数量</th></tr><tr><td>date</td><td>str</td><td>u32</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>2022-07-11</td><td>&quot;000900&quot;</td><td>1</td><td>&quot;湘财&quot;</td><td>&quot;09:33:37&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>34400.0</td></tr><tr><td>2022-07-11</td><td>&quot;002462&quot;</td><td>5</td><td>&quot;湘财&quot;</td><td>&quot;09:38:16&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>10400.0</td></tr><tr><td>2022-07-11</td><td>&quot;600894&quot;</td><td>3</td><td>&quot;湘财&quot;</td><td>&quot;09:36:30&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>21400.0</td></tr><tr><td>2022-07-11</td><td>&quot;601077&quot;</td><td>2</td><td>&quot;湘财&quot;</td><td>&quot;09:34:24&quot;</td><td>&quot;渝农商行&quot;</td><td>&quot;买入&quot;</td><td>3.65</td><td>38300.0</td><td>139795.0</td><td>22.37</td><td>0.0</td><td>1.38</td><td>0.0</td><td>-139818.75</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>38300.0</td></tr><tr><td>2022-07-11</td><td>&quot;601992&quot;</td><td>4</td><td>&quot;湘财&quot;</td><td>&quot;09:37:25&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;买入&quot;</td><td>2.59</td><td>54000.0</td><td>139860.0</td><td>22.38</td><td>0.0</td><td>1.42</td><td>0.0</td><td>-139883.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>54000.0</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-10-31</td><td>&quot;300132&quot;</td><td>361</td><td>&quot;海通两融&quot;</td><td>&quot;09:40:55&quot;</td><td>&quot;青松股份&quot;</td><td>&quot;买入&quot;</td><td>5.21</td><td>9600.0</td><td>50016.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50021.0</td><td>0.0001</td><td>0.0</td><td>0.0</td><td>9600.0</td></tr><tr><td>2023-10-31</td><td>&quot;300215&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>20000.0</td></tr><tr><td>2023-10-31</td><td>&quot;600525&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>8500.0</td></tr><tr><td>2023-10-31</td><td>&quot;603214&quot;</td><td>360</td><td>&quot;海通两融&quot;</td><td>&quot;09:39:57&quot;</td><td>&quot;爱婴室&quot;</td><td>&quot;买入&quot;</td><td>15.84</td><td>3100.0</td><td>49104.0</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-49109.51</td><td>0.000102</td><td>0.0</td><td>0.00001</td><td>3100.0</td></tr><tr><td>2023-10-31</td><td>&quot;688660&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>20200.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (4_489, 19)\\n\",\n",
    "       \"┌────────────┬──────────┬──────┬──────────┬───┬──────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 日期       ┆ 证券代码 ┆ 序号 ┆ 券商     ┆ … ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 ┆ 结余数量 │\\n\",\n",
    "       \"│ ---        ┆ ---      ┆ ---  ┆ ---      ┆   ┆ ---      ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ date       ┆ str      ┆ u32  ┆ str      ┆   ┆ f64      ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞════════════╪══════════╪══════╪══════════╪═══╪══════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000900   ┆ 1    ┆ 湘财     ┆ … ┆ 0.00016  ┆ 0.0      ┆ 0.00001  ┆ 34400.0  │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 002462   ┆ 5    ┆ 湘财     ┆ … ┆ 0.00016  ┆ 0.0      ┆ 0.00001  ┆ 10400.0  │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 600894   ┆ 3    ┆ 湘财     ┆ … ┆ 0.00016  ┆ 0.0      ┆ 0.00001  ┆ 21400.0  │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 601077   ┆ 2    ┆ 湘财     ┆ … ┆ 0.00016  ┆ 0.0      ┆ 0.00001  ┆ 38300.0  │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 601992   ┆ 4    ┆ 湘财     ┆ … ┆ 0.00016  ┆ 0.0      ┆ 0.00001  ┆ 54000.0  │\\n\",\n",
    "       \"│ …          ┆ …        ┆ …    ┆ …        ┆ … ┆ …        ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 300132   ┆ 361  ┆ 海通两融 ┆ … ┆ 0.0001   ┆ 0.0      ┆ 0.0      ┆ 9600.0   │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 300215   ┆ null ┆ null     ┆ … ┆ null     ┆ null     ┆ null     ┆ 20000.0  │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 600525   ┆ null ┆ null     ┆ … ┆ null     ┆ null     ┆ null     ┆ 8500.0   │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 603214   ┆ 360  ┆ 海通两融 ┆ … ┆ 0.000102 ┆ 0.0      ┆ 0.00001  ┆ 3100.0   │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688660   ┆ null ┆ null     ┆ … ┆ null     ┆ null     ┆ null     ┆ 20200.0  │\\n\",\n",
    "       \"└────────────┴──────────┴──────┴──────────┴───┴──────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 24,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d2\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 25,\n",
    "   \"id\": \"4ebd628b-65d5-4886-b6bc-6caf21177bba\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (149,)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>证券代码</th></tr><tr><td>str</td></tr></thead><tbody><tr><td>&quot;002462&quot;</td></tr><tr><td>&quot;002381&quot;</td></tr><tr><td>&quot;002111&quot;</td></tr><tr><td>&quot;600273&quot;</td></tr><tr><td>&quot;605196&quot;</td></tr><tr><td>&hellip;</td></tr><tr><td>&quot;002382&quot;</td></tr><tr><td>&quot;688393&quot;</td></tr><tr><td>&quot;002661&quot;</td></tr><tr><td>&quot;605288&quot;</td></tr><tr><td>&quot;300464&quot;</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (149,)\\n\",\n",
    "       \"Series: '证券代码' [str]\\n\",\n",
    "       \"[\\n\",\n",
    "       \"\\t\\\"002462\\\"\\n\",\n",
    "       \"\\t\\\"002381\\\"\\n\",\n",
    "       \"\\t\\\"002111\\\"\\n\",\n",
    "       \"\\t\\\"600273\\\"\\n\",\n",
    "       \"\\t\\\"605196\\\"\\n\",\n",
    "       \"\\t…\\n\",\n",
    "       \"\\t\\\"002382\\\"\\n\",\n",
    "       \"\\t\\\"688393\\\"\\n\",\n",
    "       \"\\t\\\"002661\\\"\\n\",\n",
    "       \"\\t\\\"605288\\\"\\n\",\n",
    "       \"\\t\\\"300464\\\"\\n\",\n",
    "       \"]\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 25,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d1[\\\"证券代码\\\"].unique()\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 26,\n",
    "   \"id\": \"c35174a8-5926-4863-8b95-21e58fc407f2\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"ts_codes = (\\n\",\n",
    "    \"    d1.select(\\n\",\n",
    "    \"        证券代码=(\\n\",\n",
    "    \"            pl.when(pl.col.证券代码.str.head(1).is_in([\\\"0\\\", \\\"3\\\"]))\\n\",\n",
    "    \"            .then(pl.format(\\\"{}.SZ\\\", pl.col.证券代码))\\n\",\n",
    "    \"            .when(pl.col.证券代码.str.head(1) == \\\"6\\\")\\n\",\n",
    "    \"            .then(pl.format(\\\"{}.SH\\\", pl.col.证券代码))\\n\",\n",
    "    \"        ),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .to_series()\\n\",\n",
    "    \"    .unique()\\n\",\n",
    "    \"    .sort()\\n\",\n",
    "    \"    .to_list()\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 27,\n",
    "   \"id\": \"de19f05a-f07f-427a-bc39-245e3c4334bf\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"149\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 27,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"len(ts_codes)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 28,\n",
    "   \"id\": \"7d5e69bc-51d0-4726-9e40-fbb8b88a01bb\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"from tqdm.notebook import tqdm\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 32,\n",
    "   \"id\": \"49fb2eff-fe37-4fe9-851a-6a4abdd24c68\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"cec1146252dc4f95b9217a3480d5453b\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"  0%|          | 0/149 [00:00<?, ?it/s]\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"hq = [\\n\",\n",
    "    \"    pl.from_pandas(\\n\",\n",
    "    \"        pro.daily(\\n\",\n",
    "    \"            ts_code=ts_code,\\n\",\n",
    "    \"            start_date=format(start_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \"            end_date=format(end_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \"        )\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    for ts_code in tqdm(ts_codes)\\n\",\n",
    "    \"]\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 33,\n",
    "   \"id\": \"0843f6bd-c4db-4e5f-aa17-40bcc35d9624\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"149\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 33,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"len(hq)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 36,\n",
    "   \"id\": \"4eafc8d5-cf12-4a86-9b22-7dbc6da91488\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"hq = pl.concat(hq)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 38,\n",
    "   \"id\": \"cdd4af26-529e-40b8-806f-18f9ddef9949\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"name\": \"stdout\",\n",
    "     \"output_type\": \"stream\",\n",
    "     \"text\": [\n",
    "      \"/c/Users/mate/repo/week08\\n\"\n",
    "     ]\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"!pwd\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 39,\n",
    "   \"id\": \"c6c22c77-e693-40d0-8b7f-09bb3ff3f496\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"hq.write_parquet(\\\"daily.parquet\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 48,\n",
    "   \"id\": \"5af90623-687b-4d88-a37c-69885beeb57d\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"hq = pl.read_parquet(\\\"daily.parquet\\\")\\n\",\n",
    "    \"hq = hq.with_columns(\\n\",\n",
    "    \"    pl.col(\\\"ts_code\\\").str.head(6),\\n\",\n",
    "    \"    pl.col(\\\"trade_date\\\").str.to_date(\\\"%Y%m%d\\\"),\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 61,\n",
    "   \"id\": \"bca2eaa9-33ea-4226-b54d-4d346948c936\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (358, 28)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th><th>open</th><th>high</th><th>low</th><th>close</th><th>pre_close</th><th>change</th><th>pct_chg</th><th>vol</th><th>amount</th><th>vratio</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>237</td><td>&quot;湘财&quot;</td><td>2023-05-09</td><td>&quot;09:33:16&quot;</td><td>&quot;601166&quot;</td><td>&quot;兴业银行&quot;</td><td>&quot;卖出&quot;</td><td>17.75</td><td>3000.0</td><td>53250.0</td><td>8.52</td><td>53.25</td><td>0.53</td><td>0.0</td><td>53187.7</td><td>0.00016</td><td>0.001</td><td>0.00001</td><td>17.77</td><td>17.94</td><td>17.5</td><td>17.56</td><td>17.63</td><td>-0.07</td><td>-0.3971</td><td>1.6276e6</td><td>2.8810e6</td><td>0.000018</td></tr><tr><td>48</td><td>&quot;湘财&quot;</td><td>2022-10-25</td><td>&quot;09:30:19&quot;</td><td>&quot;300368&quot;</td><td>&quot;汇金股份&quot;</td><td>&quot;卖出&quot;</td><td>6.2</td><td>100.0</td><td>620.0</td><td>0.1</td><td>0.62</td><td>0.01</td><td>0.0</td><td>619.28</td><td>0.000161</td><td>0.001</td><td>0.000016</td><td>6.18</td><td>6.25</td><td>5.95</td><td>6.06</td><td>6.2</td><td>-0.14</td><td>-2.2581</td><td>49219.99</td><td>29911.915</td><td>0.00002</td></tr><tr><td>49</td><td>&quot;湘财&quot;</td><td>2022-10-25</td><td>&quot;09:30:39&quot;</td><td>&quot;002996&quot;</td><td>&quot;顺博合金&quot;</td><td>&quot;卖出&quot;</td><td>13.64</td><td>100.0</td><td>1364.0</td><td>0.22</td><td>1.36</td><td>0.01</td><td>0.0</td><td>1362.42</td><td>0.000161</td><td>0.000997</td><td>0.000007</td><td>13.57</td><td>13.93</td><td>13.26</td><td>13.82</td><td>13.64</td><td>0.18</td><td>1.3196</td><td>38258.22</td><td>52122.119</td><td>0.000026</td></tr><tr><td>235</td><td>&quot;湘财&quot;</td><td>2023-04-25</td><td>&quot;13:35:07&quot;</td><td>&quot;601166&quot;</td><td>&quot;兴业银行&quot;</td><td>&quot;买入&quot;</td><td>17.15</td><td>3000.0</td><td>51450.0</td><td>8.23</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-51458.74</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>16.96</td><td>17.29</td><td>16.96</td><td>17.27</td><td>16.93</td><td>0.34</td><td>2.0083</td><td>995234.22</td><td>1.7071e6</td><td>0.00003</td></tr><tr><td>46</td><td>&quot;湘财&quot;</td><td>2022-10-25</td><td>&quot;09:25:00&quot;</td><td>&quot;002998&quot;</td><td>&quot;优彩资源&quot;</td><td>&quot;卖出&quot;</td><td>6.73</td><td>100.0</td><td>673.0</td><td>0.11</td><td>0.67</td><td>0.01</td><td>0.0</td><td>672.22</td><td>0.000163</td><td>0.000996</td><td>0.000015</td><td>6.73</td><td>6.73</td><td>6.56</td><td>6.64</td><td>6.72</td><td>-0.08</td><td>-1.1905</td><td>16145.0</td><td>10687.614</td><td>0.000062</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>30</td><td>&quot;湘财&quot;</td><td>2022-10-11</td><td>&quot;09:41:06&quot;</td><td>&quot;600231&quot;</td><td>&quot;凌钢股份&quot;</td><td>&quot;买入&quot;</td><td>2.2</td><td>62700.0</td><td>137940.0</td><td>22.07</td><td>0.0</td><td>1.29</td><td>0.0</td><td>-137963.36</td><td>0.00016</td><td>0.0</td><td>0.000009</td><td>2.21</td><td>2.22</td><td>2.15</td><td>2.2</td><td>2.21</td><td>-0.01</td><td>-0.4525</td><td>61371.2</td><td>13386.328</td><td>0.010217</td></tr><tr><td>3</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:36:30&quot;</td><td>&quot;600894&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>6.57</td><td>6.57</td><td>6.49</td><td>6.51</td><td>6.57</td><td>-0.06</td><td>-0.9132</td><td>20737.5</td><td>13537.134</td><td>0.010319</td></tr><tr><td>142</td><td>&quot;湘财&quot;</td><td>2023-02-21</td><td>&quot;09:37:16&quot;</td><td>&quot;300385&quot;</td><td>&quot;雪浪环境&quot;</td><td>&quot;买入&quot;</td><td>6.5293</td><td>11500.0</td><td>75087.0</td><td>12.01</td><td>0.0</td><td>0.77</td><td>0.0</td><td>-75099.01</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>6.53</td><td>6.59</td><td>6.45</td><td>6.52</td><td>6.5</td><td>0.02</td><td>0.3077</td><td>11136.0</td><td>7250.686</td><td>0.010327</td></tr><tr><td>152</td><td>&quot;湘财&quot;</td><td>2023-03-01</td><td>&quot;09:31:46&quot;</td><td>&quot;688069&quot;</td><td>&quot;德林海环保&quot;</td><td>&quot;卖出&quot;</td><td>28.2838</td><td>2600.0</td><td>73538.0</td><td>11.77</td><td>73.58</td><td>0.77</td><td>0.0</td><td>73451.88</td><td>0.00016</td><td>0.001001</td><td>0.00001</td><td>28.52</td><td>28.86</td><td>28.27</td><td>28.67</td><td>28.54</td><td>0.13</td><td>0.4555</td><td>2416.06</td><td>6897.976</td><td>0.010761</td></tr><tr><td>27</td><td>&quot;湘财&quot;</td><td>2022-10-11</td><td>&quot;09:37:32&quot;</td><td>&quot;600261&quot;</td><td>&quot;阳光照明&quot;</td><td>&quot;买入&quot;</td><td>3.1134</td><td>44600.0</td><td>138857.0</td><td>22.22</td><td>0.0</td><td>1.33</td><td>0.0</td><td>-138880.55</td><td>0.00016</td><td>0.0</td><td>0.00001</td><td>3.14</td><td>3.15</td><td>3.06</td><td>3.13</td><td>3.11</td><td>0.02</td><td>0.6431</td><td>41397.03</td><td>12872.499</td><td>0.010774</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (358, 28)\\n\",\n",
    "       \"┌──────┬──────┬────────────┬──────────┬───┬─────────┬───────────┬───────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商 ┆ 交易日期   ┆ 交易时间 ┆ … ┆ pct_chg ┆ vol       ┆ amount    ┆ vratio   │\\n\",\n",
    "       \"│ ---  ┆ ---  ┆ ---        ┆ ---      ┆   ┆ ---     ┆ ---       ┆ ---       ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str  ┆ date       ┆ str      ┆   ┆ f64     ┆ f64       ┆ f64       ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════╪════════════╪══════════╪═══╪═════════╪═══════════╪═══════════╪══════════╡\\n\",\n",
    "       \"│ 237  ┆ 湘财 ┆ 2023-05-09 ┆ 09:33:16 ┆ … ┆ -0.3971 ┆ 1.6276e6  ┆ 2.8810e6  ┆ 0.000018 │\\n\",\n",
    "       \"│ 48   ┆ 湘财 ┆ 2022-10-25 ┆ 09:30:19 ┆ … ┆ -2.2581 ┆ 49219.99  ┆ 29911.915 ┆ 0.00002  │\\n\",\n",
    "       \"│ 49   ┆ 湘财 ┆ 2022-10-25 ┆ 09:30:39 ┆ … ┆ 1.3196  ┆ 38258.22  ┆ 52122.119 ┆ 0.000026 │\\n\",\n",
    "       \"│ 235  ┆ 湘财 ┆ 2023-04-25 ┆ 13:35:07 ┆ … ┆ 2.0083  ┆ 995234.22 ┆ 1.7071e6  ┆ 0.00003  │\\n\",\n",
    "       \"│ 46   ┆ 湘财 ┆ 2022-10-25 ┆ 09:25:00 ┆ … ┆ -1.1905 ┆ 16145.0   ┆ 10687.614 ┆ 0.000062 │\\n\",\n",
    "       \"│ …    ┆ …    ┆ …          ┆ …        ┆ … ┆ …       ┆ …         ┆ …         ┆ …        │\\n\",\n",
    "       \"│ 30   ┆ 湘财 ┆ 2022-10-11 ┆ 09:41:06 ┆ … ┆ -0.4525 ┆ 61371.2   ┆ 13386.328 ┆ 0.010217 │\\n\",\n",
    "       \"│ 3    ┆ 湘财 ┆ 2022-07-11 ┆ 09:36:30 ┆ … ┆ -0.9132 ┆ 20737.5   ┆ 13537.134 ┆ 0.010319 │\\n\",\n",
    "       \"│ 142  ┆ 湘财 ┆ 2023-02-21 ┆ 09:37:16 ┆ … ┆ 0.3077  ┆ 11136.0   ┆ 7250.686  ┆ 0.010327 │\\n\",\n",
    "       \"│ 152  ┆ 湘财 ┆ 2023-03-01 ┆ 09:31:46 ┆ … ┆ 0.4555  ┆ 2416.06   ┆ 6897.976  ┆ 0.010761 │\\n\",\n",
    "       \"│ 27   ┆ 湘财 ┆ 2022-10-11 ┆ 09:37:32 ┆ … ┆ 0.6431  ┆ 41397.03  ┆ 12872.499 ┆ 0.010774 │\\n\",\n",
    "       \"└──────┴──────┴────────────┴──────────┴───┴─────────┴───────────┴───────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 61,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d1.join(\\n\",\n",
    "    \"    hq, left_on=[\\\"交易日期\\\", \\\"证券代码\\\"], right_on=[\\\"trade_date\\\", \\\"ts_code\\\"], how=\\\"left\\\"\\n\",\n",
    "    \").with_columns(\\n\",\n",
    "    \"    vratio=pl.col.成交数量 / 100 / pl.col.vol,\\n\",\n",
    "    \").sort(\\\"vratio\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 63,\n",
    "   \"id\": \"340d8ff2-790e-4994-aeb6-fcba6559908c\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (72_671, 19)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>日期</th><th>证券代码</th><th>序号</th><th>券商</th><th>交易时间</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th><th>结余数量</th></tr><tr><td>date</td><td>str</td><td>u32</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>2022-07-11</td><td>&quot;000096&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2022-07-11</td><td>&quot;000532&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2022-07-11</td><td>&quot;000559&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2022-07-11</td><td>&quot;000599&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2022-07-11</td><td>&quot;000655&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-10-31</td><td>&quot;688299&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2023-10-31</td><td>&quot;688321&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2023-10-31</td><td>&quot;688360&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2023-10-31</td><td>&quot;688393&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>0.0</td></tr><tr><td>2023-10-31</td><td>&quot;688660&quot;</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>null</td><td>20200.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (72_671, 19)\\n\",\n",
    "       \"┌────────────┬──────────┬──────┬──────┬───┬──────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 日期       ┆ 证券代码 ┆ 序号 ┆ 券商 ┆ … ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 ┆ 结余数量 │\\n\",\n",
    "       \"│ ---        ┆ ---      ┆ ---  ┆ ---  ┆   ┆ ---      ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ date       ┆ str      ┆ u32  ┆ str  ┆   ┆ f64      ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞════════════╪══════════╪══════╪══════╪═══╪══════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000096   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000532   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000559   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000599   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2022-07-11 ┆ 000655   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ …          ┆ …        ┆ …    ┆ …    ┆ … ┆ …        ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688299   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688321   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688360   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688393   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 0.0      │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 688660   ┆ null ┆ null ┆ … ┆ null     ┆ null     ┆ null     ┆ 20200.0  │\\n\",\n",
    "       \"└────────────┴──────────┴──────┴──────┴───┴──────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 63,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d3 = (\\n\",\n",
    "    \"    k.join(\\n\",\n",
    "    \"        d1, left_on=[\\\"日期\\\", \\\"证券代码\\\"], right_on=[\\\"交易日期\\\", \\\"证券代码\\\"], how=\\\"left\\\"\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .sort(\\\"日期\\\", \\\"证券代码\\\")\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        结余数量=(\\n\",\n",
    "    \"            pl.when(pl.col(\\\"买卖标志\\\") == \\\"买入\\\")\\n\",\n",
    "    \"            .then(pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .when(pl.col(\\\"买卖标志\\\") == \\\"卖出\\\")\\n\",\n",
    "    \"            .then(-pl.col(\\\"成交数量\\\"))\\n\",\n",
    "    \"            .otherwise(0)\\n\",\n",
    "    \"            .cum_sum()\\n\",\n",
    "    \"            .over(\\\"证券代码\\\")\\n\",\n",
    "    \"        ),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \")\\n\",\n",
    "    \"d3\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 77,\n",
    "   \"id\": \"c7997b82-6453-4f8e-adcf-d6dd3cb9a7c5\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (358, 18)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>序号</th><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>手续费率</th><th>印花税率</th><th>过户费率</th></tr><tr><td>u32</td><td>str</td><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>1</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:33:37&quot;</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>2</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:34:24&quot;</td><td>&quot;601077&quot;</td><td>&quot;渝农商行&quot;</td><td>&quot;买入&quot;</td><td>3.65</td><td>38300.0</td><td>139795.0</td><td>22.37</td><td>0.0</td><td>1.38</td><td>0.0</td><td>-139818.75</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>3</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:36:30&quot;</td><td>&quot;600894&quot;</td><td>&quot;广日股份&quot;</td><td>&quot;买入&quot;</td><td>6.54</td><td>21400.0</td><td>139956.0</td><td>22.39</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-139979.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>4</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:37:25&quot;</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;买入&quot;</td><td>2.59</td><td>54000.0</td><td>139860.0</td><td>22.38</td><td>0.0</td><td>1.42</td><td>0.0</td><td>-139883.8</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>5</td><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>&quot;09:38:16&quot;</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>0.00016</td><td>0.0</td><td>0.00001</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>359</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:31:53&quot;</td><td>&quot;002956&quot;</td><td>&quot;西麦食品&quot;</td><td>&quot;卖出&quot;</td><td>14.13</td><td>5000.0</td><td>70650.0</td><td>6.74</td><td>35.35</td><td>0.0</td><td>0.0</td><td>70607.91</td><td>0.000095</td><td>0.0005</td><td>0.0</td></tr><tr><td>360</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:39:57&quot;</td><td>&quot;603214&quot;</td><td>&quot;爱婴室&quot;</td><td>&quot;买入&quot;</td><td>15.84</td><td>3100.0</td><td>49104.0</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>-49109.51</td><td>0.000102</td><td>0.0</td><td>0.00001</td></tr><tr><td>361</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:40:55&quot;</td><td>&quot;300132&quot;</td><td>&quot;青松股份&quot;</td><td>&quot;买入&quot;</td><td>5.21</td><td>9600.0</td><td>50016.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50021.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr><tr><td>362</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:43:13&quot;</td><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>&quot;买入&quot;</td><td>5.91</td><td>8400.0</td><td>49644.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49649.0</td><td>0.000101</td><td>0.0</td><td>0.0</td></tr><tr><td>363</td><td>&quot;海通两融&quot;</td><td>2023-10-31</td><td>&quot;09:44:45&quot;</td><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>&quot;买入&quot;</td><td>9.24</td><td>5400.0</td><td>49896.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49901.0</td><td>0.0001</td><td>0.0</td><td>0.0</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (358, 18)\\n\",\n",
    "       \"┌──────┬──────────┬────────────┬──────────┬───┬────────────┬──────────┬──────────┬──────────┐\\n\",\n",
    "       \"│ 序号 ┆ 券商     ┆ 交易日期   ┆ 交易时间 ┆ … ┆ 发生金额   ┆ 手续费率 ┆ 印花税率 ┆ 过户费率 │\\n\",\n",
    "       \"│ ---  ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---        ┆ ---      ┆ ---      ┆ ---      │\\n\",\n",
    "       \"│ u32  ┆ str      ┆ date       ┆ str      ┆   ┆ f64        ┆ f64      ┆ f64      ┆ f64      │\\n\",\n",
    "       \"╞══════╪══════════╪════════════╪══════════╪═══╪════════════╪══════════╪══════════╪══════════╡\\n\",\n",
    "       \"│ 1    ┆ 湘财     ┆ 2022-07-11 ┆ 09:33:37 ┆ … ┆ -139342.29 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 2    ┆ 湘财     ┆ 2022-07-11 ┆ 09:34:24 ┆ … ┆ -139818.75 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 3    ┆ 湘财     ┆ 2022-07-11 ┆ 09:36:30 ┆ … ┆ -139979.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 4    ┆ 湘财     ┆ 2022-07-11 ┆ 09:37:25 ┆ … ┆ -139883.8  ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 5    ┆ 湘财     ┆ 2022-07-11 ┆ 09:38:16 ┆ … ┆ -140526.48 ┆ 0.00016  ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ …    ┆ …        ┆ …          ┆ …        ┆ … ┆ …          ┆ …        ┆ …        ┆ …        │\\n\",\n",
    "       \"│ 359  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:31:53 ┆ … ┆ 70607.91   ┆ 0.000095 ┆ 0.0005   ┆ 0.0      │\\n\",\n",
    "       \"│ 360  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:39:57 ┆ … ┆ -49109.51  ┆ 0.000102 ┆ 0.0      ┆ 0.00001  │\\n\",\n",
    "       \"│ 361  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:40:55 ┆ … ┆ -50021.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 362  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:43:13 ┆ … ┆ -49649.0   ┆ 0.000101 ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"│ 363  ┆ 海通两融 ┆ 2023-10-31 ┆ 09:44:45 ┆ … ┆ -49901.0   ┆ 0.0001   ┆ 0.0      ┆ 0.0      │\\n\",\n",
    "       \"└──────┴──────────┴────────────┴──────────┴───┴────────────┴──────────┴──────────┴──────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 77,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d1\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 87,\n",
    "   \"id\": \"b87c90f3-1ec2-4d3c-a63d-ff10b373d101\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (478, 6)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>日期</th><th>持股市值</th><th>发生金额</th><th>转账金额</th><th>现金余额</th><th>总资产</th></tr><tr><td>date</td><td>f64</td><td>f64</td><td>i32</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>2022-07-11</td><td>703040.0</td><td>-699551.12</td><td>1000000</td><td>300448.88</td><td>1.0035e6</td></tr><tr><td>2022-07-12</td><td>707714.0</td><td>0.0</td><td>0</td><td>300448.88</td><td>1.0082e6</td></tr><tr><td>2022-07-13</td><td>713855.0</td><td>0.0</td><td>0</td><td>300448.88</td><td>1.0143e6</td></tr><tr><td>2022-07-14</td><td>710079.0</td><td>0.0</td><td>0</td><td>300448.88</td><td>1.0105e6</td></tr><tr><td>2022-07-15</td><td>692377.0</td><td>0.0</td><td>0</td><td>300448.88</td><td>992825.88</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-10-27</td><td>571195.0</td><td>0.0</td><td>0</td><td>510845.96</td><td>1.0820e6</td></tr><tr><td>2023-10-28</td><td>571195.0</td><td>0.0</td><td>0</td><td>510845.96</td><td>1.0820e6</td></tr><tr><td>2023-10-29</td><td>571195.0</td><td>0.0</td><td>0</td><td>510845.96</td><td>1.0820e6</td></tr><tr><td>2023-10-30</td><td>686345.0</td><td>-94884.93</td><td>0</td><td>415961.03</td><td>1.1023e6</td></tr><tr><td>2023-10-31</td><td>748947.0</td><td>6490.78</td><td>0</td><td>422451.81</td><td>1.1714e6</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (478, 6)\\n\",\n",
    "       \"┌────────────┬──────────┬────────────┬──────────┬───────────┬───────────┐\\n\",\n",
    "       \"│ 日期       ┆ 持股市值 ┆ 发生金额   ┆ 转账金额 ┆ 现金余额  ┆ 总资产    │\\n\",\n",
    "       \"│ ---        ┆ ---      ┆ ---        ┆ ---      ┆ ---       ┆ ---       │\\n\",\n",
    "       \"│ date       ┆ f64      ┆ f64        ┆ i32      ┆ f64       ┆ f64       │\\n\",\n",
    "       \"╞════════════╪══════════╪════════════╪══════════╪═══════════╪═══════════╡\\n\",\n",
    "       \"│ 2022-07-11 ┆ 703040.0 ┆ -699551.12 ┆ 1000000  ┆ 300448.88 ┆ 1.0035e6  │\\n\",\n",
    "       \"│ 2022-07-12 ┆ 707714.0 ┆ 0.0        ┆ 0        ┆ 300448.88 ┆ 1.0082e6  │\\n\",\n",
    "       \"│ 2022-07-13 ┆ 713855.0 ┆ 0.0        ┆ 0        ┆ 300448.88 ┆ 1.0143e6  │\\n\",\n",
    "       \"│ 2022-07-14 ┆ 710079.0 ┆ 0.0        ┆ 0        ┆ 300448.88 ┆ 1.0105e6  │\\n\",\n",
    "       \"│ 2022-07-15 ┆ 692377.0 ┆ 0.0        ┆ 0        ┆ 300448.88 ┆ 992825.88 │\\n\",\n",
    "       \"│ …          ┆ …        ┆ …          ┆ …        ┆ …         ┆ …         │\\n\",\n",
    "       \"│ 2023-10-27 ┆ 571195.0 ┆ 0.0        ┆ 0        ┆ 510845.96 ┆ 1.0820e6  │\\n\",\n",
    "       \"│ 2023-10-28 ┆ 571195.0 ┆ 0.0        ┆ 0        ┆ 510845.96 ┆ 1.0820e6  │\\n\",\n",
    "       \"│ 2023-10-29 ┆ 571195.0 ┆ 0.0        ┆ 0        ┆ 510845.96 ┆ 1.0820e6  │\\n\",\n",
    "       \"│ 2023-10-30 ┆ 686345.0 ┆ -94884.93  ┆ 0        ┆ 415961.03 ┆ 1.1023e6  │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 748947.0 ┆ 6490.78    ┆ 0        ┆ 422451.81 ┆ 1.1714e6  │\\n\",\n",
    "       \"└────────────┴──────────┴────────────┴──────────┴───────────┴───────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 87,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d4 = (\\n\",\n",
    "    \"    d3.join(\\n\",\n",
    "    \"        hq,\\n\",\n",
    "    \"        left_on=[\\\"日期\\\", \\\"证券代码\\\"],\\n\",\n",
    "    \"        right_on=[\\\"trade_date\\\", \\\"ts_code\\\"],\\n\",\n",
    "    \"        how=\\\"left\\\",\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .sort(\\\"证券代码\\\", \\\"日期\\\")\\n\",\n",
    "    \"    .with_columns(close=pl.col.close.fill_null(strategy=\\\"forward\\\").over(\\\"证券代码\\\"))\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        持股市值=pl.col.结余数量 * pl.col.close,\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .group_by(\\\"日期\\\")\\n\",\n",
    "    \"    .agg(\\n\",\n",
    "    \"        pl.col.持股市值.sum(),\\n\",\n",
    "    \"        pl.col.发生金额.sum(),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .sort(\\\"日期\\\")\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        转账金额=pl.when(pl.int_range(0, pl.len()) == 0).then(100_0000).otherwise(0),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        现金余额=(pl.col.转账金额 + pl.col.发生金额).cum_sum(),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .with_columns(总资产=pl.col.持股市值 + pl.col.现金余额)\\n\",\n",
    "    \")\\n\",\n",
    "    \"d4\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 88,\n",
    "   \"id\": \"ee394c2a-ce64-4773-96d9-4989fb887b31\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"1ba5e56f327946c696cb2cee890482ad\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"PerspectiveWidget(binding_mode='server', columns=['日期', '持股市值', '发生金额', '转账金额', '现金余额', '总资产'], table_name='0.…\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 88,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"PerspectiveWidget(d4)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 92,\n",
    "   \"id\": \"2de59914-4d63-4f16-a4a4-a2afc9b01255\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"ihq = pro.index_daily(\\n\",\n",
    "    \"    ts_code=\\\"000300.SH\\\",\\n\",\n",
    "    \"    start_date=format(start_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \"    end_date=format(end_date, \\\"%Y%m%d\\\"),\\n\",\n",
    "    \"    fields=\\\"ts_code,trade_date,pct_chg\\\",\\n\",\n",
    "    \")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 94,\n",
    "   \"id\": \"06720c88-e216-4b0c-87b0-3effeac69373\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"pl.from_pandas(ihq).write_parquet(\\\"index_daily.parquet\\\")\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 101,\n",
    "   \"id\": \"323712c5-db07-42c2-9226-9deb70ccebc5\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (318, 5)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>ts_code</th><th>trade_date</th><th>pct_chg</th><th>car</th><th>沪深300</th></tr><tr><td>str</td><td>date</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;000300.SH&quot;</td><td>2022-07-11</td><td>0.983254</td><td>0.983254</td><td>983254.0</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2022-07-12</td><td>0.990585</td><td>0.973997</td><td>973996.66359</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2022-07-13</td><td>1.001818</td><td>0.975767</td><td>975767.389524</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2022-07-14</td><td>1.000142</td><td>0.975906</td><td>975905.948494</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2022-07-15</td><td>0.982983</td><td>0.959299</td><td>959298.956968</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2023-10-25</td><td>1.004969</td><td>0.791288</td><td>791288.453778</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2023-10-26</td><td>1.002764</td><td>0.793476</td><td>793475.575065</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2023-10-27</td><td>1.013727</td><td>0.804368</td><td>804367.614284</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2023-10-30</td><td>1.006003</td><td>0.809196</td><td>809196.233072</td></tr><tr><td>&quot;000300.SH&quot;</td><td>2023-10-31</td><td>0.996856</td><td>0.806652</td><td>806652.120115</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (318, 5)\\n\",\n",
    "       \"┌───────────┬────────────┬──────────┬──────────┬───────────────┐\\n\",\n",
    "       \"│ ts_code   ┆ trade_date ┆ pct_chg  ┆ car      ┆ 沪深300       │\\n\",\n",
    "       \"│ ---       ┆ ---        ┆ ---      ┆ ---      ┆ ---           │\\n\",\n",
    "       \"│ str       ┆ date       ┆ f64      ┆ f64      ┆ f64           │\\n\",\n",
    "       \"╞═══════════╪════════════╪══════════╪══════════╪═══════════════╡\\n\",\n",
    "       \"│ 000300.SH ┆ 2022-07-11 ┆ 0.983254 ┆ 0.983254 ┆ 983254.0      │\\n\",\n",
    "       \"│ 000300.SH ┆ 2022-07-12 ┆ 0.990585 ┆ 0.973997 ┆ 973996.66359  │\\n\",\n",
    "       \"│ 000300.SH ┆ 2022-07-13 ┆ 1.001818 ┆ 0.975767 ┆ 975767.389524 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2022-07-14 ┆ 1.000142 ┆ 0.975906 ┆ 975905.948494 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2022-07-15 ┆ 0.982983 ┆ 0.959299 ┆ 959298.956968 │\\n\",\n",
    "       \"│ …         ┆ …          ┆ …        ┆ …        ┆ …             │\\n\",\n",
    "       \"│ 000300.SH ┆ 2023-10-25 ┆ 1.004969 ┆ 0.791288 ┆ 791288.453778 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2023-10-26 ┆ 1.002764 ┆ 0.793476 ┆ 793475.575065 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2023-10-27 ┆ 1.013727 ┆ 0.804368 ┆ 804367.614284 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2023-10-30 ┆ 1.006003 ┆ 0.809196 ┆ 809196.233072 │\\n\",\n",
    "       \"│ 000300.SH ┆ 2023-10-31 ┆ 0.996856 ┆ 0.806652 ┆ 806652.120115 │\\n\",\n",
    "       \"└───────────┴────────────┴──────────┴──────────┴───────────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 101,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"ihq = pl.read_parquet(\\\"index_daily.parquet\\\")\\n\",\n",
    "    \"ihq = (\\n\",\n",
    "    \"    ihq.with_columns(\\n\",\n",
    "    \"        pl.col.trade_date.str.to_date(\\\"%Y%m%d\\\"),\\n\",\n",
    "    \"        pl.col.pct_chg / 100 + 1,\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .sort(\\\"trade_date\\\")\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        car=pl.col.pct_chg.cum_prod(),\\n\",\n",
    "    \"    )\\n\",\n",
    "    \"    .with_columns(\\n\",\n",
    "    \"        沪深300=pl.col.car * 100_0000,\\n\",\n",
    "    \"    )\\n\",\n",
    "    \")\\n\",\n",
    "    \"ihq\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 102,\n",
    "   \"id\": \"b270e130-a84d-42e9-9bc2-f7e8a53e14a1\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"53a60f98dda84492aa7acf8bd587b7a6\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"PerspectiveWidget(binding_mode='server', columns=['ts_code', 'trade_date', 'pct_chg', 'car', '沪深300'], table_n…\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 102,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"PerspectiveWidget(ihq)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 111,\n",
    "   \"id\": \"024c229c-4ea8-4372-96b9-a12d679172cc\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/html\": [\n",
    "       \"<div><style>\\n\",\n",
    "       \".dataframe > thead > tr,\\n\",\n",
    "       \".dataframe > tbody > tr {\\n\",\n",
    "       \"  text-align: right;\\n\",\n",
    "       \"  white-space: pre-wrap;\\n\",\n",
    "       \"}\\n\",\n",
    "       \"</style>\\n\",\n",
    "       \"<small>shape: (636, 3)</small><table border=\\\"1\\\" class=\\\"dataframe\\\"><thead><tr><th>日期</th><th>资产类型</th><th>财富</th></tr><tr><td>date</td><td>str</td><td>f64</td></tr></thead><tbody><tr><td>2022-07-11</td><td>&quot;总资产&quot;</td><td>1.0035e6</td></tr><tr><td>2022-07-12</td><td>&quot;总资产&quot;</td><td>1.0082e6</td></tr><tr><td>2022-07-13</td><td>&quot;总资产&quot;</td><td>1.0143e6</td></tr><tr><td>2022-07-14</td><td>&quot;总资产&quot;</td><td>1.0105e6</td></tr><tr><td>2022-07-15</td><td>&quot;总资产&quot;</td><td>992825.88</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-10-25</td><td>&quot;沪深300&quot;</td><td>791288.453778</td></tr><tr><td>2023-10-26</td><td>&quot;沪深300&quot;</td><td>793475.575065</td></tr><tr><td>2023-10-27</td><td>&quot;沪深300&quot;</td><td>804367.614284</td></tr><tr><td>2023-10-30</td><td>&quot;沪深300&quot;</td><td>809196.233072</td></tr><tr><td>2023-10-31</td><td>&quot;沪深300&quot;</td><td>806652.120115</td></tr></tbody></table></div>\"\n",
    "      ],\n",
    "      \"text/plain\": [\n",
    "       \"shape: (636, 3)\\n\",\n",
    "       \"┌────────────┬──────────┬───────────────┐\\n\",\n",
    "       \"│ 日期       ┆ 资产类型 ┆ 财富          │\\n\",\n",
    "       \"│ ---        ┆ ---      ┆ ---           │\\n\",\n",
    "       \"│ date       ┆ str      ┆ f64           │\\n\",\n",
    "       \"╞════════════╪══════════╪═══════════════╡\\n\",\n",
    "       \"│ 2022-07-11 ┆ 总资产   ┆ 1.0035e6      │\\n\",\n",
    "       \"│ 2022-07-12 ┆ 总资产   ┆ 1.0082e6      │\\n\",\n",
    "       \"│ 2022-07-13 ┆ 总资产   ┆ 1.0143e6      │\\n\",\n",
    "       \"│ 2022-07-14 ┆ 总资产   ┆ 1.0105e6      │\\n\",\n",
    "       \"│ 2022-07-15 ┆ 总资产   ┆ 992825.88     │\\n\",\n",
    "       \"│ …          ┆ …        ┆ …             │\\n\",\n",
    "       \"│ 2023-10-25 ┆ 沪深300  ┆ 791288.453778 │\\n\",\n",
    "       \"│ 2023-10-26 ┆ 沪深300  ┆ 793475.575065 │\\n\",\n",
    "       \"│ 2023-10-27 ┆ 沪深300  ┆ 804367.614284 │\\n\",\n",
    "       \"│ 2023-10-30 ┆ 沪深300  ┆ 809196.233072 │\\n\",\n",
    "       \"│ 2023-10-31 ┆ 沪深300  ┆ 806652.120115 │\\n\",\n",
    "       \"└────────────┴──────────┴───────────────┘\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 111,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"d5 = d4.join(ihq, left_on=\\\"日期\\\", right_on=\\\"trade_date\\\")\\n\",\n",
    "    \"d5 = d5.unpivot(\\n\",\n",
    "    \"    on=[\\\"总资产\\\", \\\"沪深300\\\"], index=\\\"日期\\\", variable_name=\\\"资产类型\\\", value_name=\\\"财富\\\"\\n\",\n",
    "    \")\\n\",\n",
    "    \"d5\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": 110,\n",
    "   \"id\": \"aa204366-75ce-4a9b-8f19-63318cdf89f7\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"application/vnd.jupyter.widget-view+json\": {\n",
    "       \"model_id\": \"e2a2f3e41c64495eb5ac5ec57737bd69\",\n",
    "       \"version_major\": 2,\n",
    "       \"version_minor\": 0\n",
    "      },\n",
    "      \"text/plain\": [\n",
    "       \"PerspectiveWidget(binding_mode='server', columns=['日期', '资产类型', '财富'], table_name='0.634374931058977', theme=N…\"\n",
    "      ]\n",
    "     },\n",
    "     \"execution_count\": 110,\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"execute_result\"\n",
    "    }\n",
    "   ],\n",
    "   \"source\": [\n",
    "    \"PerspectiveWidget(d5)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"id\": \"f69a1798-b007-498e-90ae-0b4937abcf69\",\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": []\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {\n",
    "  \"kernelspec\": {\n",
    "   \"display_name\": \"Python 3 (ipykernel)\",\n",
    "   \"language\": \"python\",\n",
    "   \"name\": \"python3\"\n",
    "  },\n",
    "  \"language_info\": {\n",
    "   \"codemirror_mode\": {\n",
    "    \"name\": \"ipython\",\n",
    "    \"version\": 3\n",
    "   },\n",
    "   \"file_extension\": \".py\",\n",
    "   \"mimetype\": \"text/x-python\",\n",
    "   \"name\": \"python\",\n",
    "   \"nbconvert_exporter\": \"python\",\n",
    "   \"pygments_lexer\": \"ipython3\",\n",
    "   \"version\": \"3.12.10\"\n",
    "  }\n",
    " },\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 5\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
